<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <div id="app">
        <input type="checkbox" v-model="checkAll">全选
        <div v-for="ele in arr">
            <input type="checkbox" v-model="ele.checked">{{ele.item }}
        </div>
    </div>
</body>
<script>
    let vm = {
        data () {
            return {
                arr: [
                    { item: '吃饭', checked: false },
                    { item: '喝水', checked: false },
                    { item: '睡觉', checked: false },
                ],
                conIpt: ''
            }
        },
        computed: {
            checkAll: {
                get: function () {
                    //将没有选中的数组过滤出来
                    let arr = this.arr.filter(ele => !ele.checked)
                    // 有长度(true)，意味着有数组未被勾选，则全选框应为不勾选(false)
                    return !arr.length
                },
                set: function (newValue) {
                    console.log(newValue);
                    // 动态获取最新值,当数值发生改变则触发
                    this.arr.forEach(ele => {
                        ele.checked = newValue
                    });
                }
            },
        }
    }
    Vue.createApp(vm).mount('#app')
</script>

</html>